package com.aitaoxue.palx.api.remote;

import java.io.File;
import java.io.FileNotFoundException;
import java.sql.Date;
import java.util.Map;

import com.aitaoxue.palx.AppContext;
import com.aitaoxue.palx.api.ApiHttpClient;
import com.aitaoxue.palx.util.MD5Utils;
import com.aitaoxue.palx.util.TDevice;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class AitaoXueApi {

	// 登录
	public static void login(String username, String password,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("phone", username);
		params.put("password", password);
		params.put("roletype", "1");
		ApiHttpClient.post("Login/login", params, mHandler);
	}

	public static void getBaseList(AsyncHttpResponseHandler mhandler) {
		ApiHttpClient.post("Public/test", mhandler);
	}

	public static void getBannersUrls(AsyncHttpResponseHandler mHandler) {
		ApiHttpClient.get("Public/bannerProdPictureUrl", mHandler);
	}

	// 获取家教资金信息
	public static void getTeacherMoney(AsyncHttpResponseHandler mHandler) {
		ApiHttpClient.post("ProdIndex/getAccountNum", mHandler);
	}

	// 获取家教认证状态
	public static void getTeacherStatus(AsyncHttpResponseHandler mHandler) {
		ApiHttpClient.post("ProdIndex/getProdSystemCheckStatus", mHandler);
	}

	// 搜索
	public static void search(String page, Map<String, String> map,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("page", page);

		if (map != null) {
			for (Map.Entry<String, String> entry : map.entrySet()) {
				params.put(entry.getKey(), entry.getValue());
			}
		}

		String city_id = AppContext.getInstance().getProperty("user.cityid");

		params.put("city_id", city_id);

		ApiHttpClient.get("Search/search_student.html", params, mHandler);
	}

	// 获得订单
	public static void showOrder(String page, String state,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("page", page);
		params.put("state", state);

		ApiHttpClient.post("ProdGoodsV2/showOrder", params, mHandler);
	}

	// 查看所有日志
	public static void getProdAllRecords(String page,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("page", page);

		ApiHttpClient.post("ProdRecordsV2/getProdAllRecords", params, mHandler);
	}

	// 获得聊天用户的信息
	public static void getUserInfo(String userId,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("userId", userId);

		ApiHttpClient.post("IM/IMGetHeaderAndName", params, mHandler);
	}

	// 创建用户的token
	public static void createIMToken(AsyncHttpResponseHandler mHandler) {
		ApiHttpClient.post("IM/creatIMToken", mHandler);
	}

	// 家教个人资料
	public static void getProdInfo(String prodId,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("prod_id", prodId);
		ApiHttpClient.post("ProdInfo/getProdInfoByProdId", params, mHandler);
	}

	// 家教自己的资料
	public static void getProdMyselfInfoByProdId(
			AsyncHttpResponseHandler mHandler) {
		ApiHttpClient.post("ProdInfo/getProdMyselfInfoByProdId", mHandler);
	}

	// 获取客户的用户信息
	public static void getCustomerInfo(String page,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("page", page);
		ApiHttpClient.post("ProdClient/getUserInfo", params, mHandler);
	}

	// 获取客户的错题本类别
	public static void getUserErrorBook(String userId,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("user_id", userId);
		ApiHttpClient.post("ProdClient/getUserErrorBook", params, mHandler);
	}

	// 获取客户的错题本
	public static void selectErrorBookByDays(Map<String, String> map,
			String user_id, String page, String order,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("page", page);
		params.put("user_id", user_id);
		params.put("bool", order);

		if (map != null) {
			for (Map.Entry<String, String> entry : map.entrySet()) {
				params.put(entry.getKey(), entry.getValue());
			}
		}

		ApiHttpClient
				.post("ProdClient/selectErrorBookByDays", params, mHandler);
	}

	// 获取头像，名字等信息
	public static void getProdInfoIndex(AsyncHttpResponseHandler mHandler) {
		ApiHttpClient.post("ProdInfo/getProdInfoIndex", mHandler);
	}

	// 上传头像
	public static void UploadHeader(File file, AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		try {
			params.put("myfile", file);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		ApiHttpClient.post("UploadFile/uploadHeadOnly", params, mHandler);
	}

	// 放弃订单
	public static void orderWaive(String orderId,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("id", orderId);
		ApiHttpClient.post("ProdGoodsV2/orderWaive", params, mHandler);
	}

	// 确认授课
	public static void orderEnsure(String orderId,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("id", orderId);
		ApiHttpClient.post("ProdGoodsV2/orderEnsure", params, mHandler);
	}

	// 提醒确认授课
	public static void remainComfirm(String orderId, String number,
			String date, AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("order_id", orderId);
		params.put("number", number);
		params.put("date", date);

		ApiHttpClient.post("ProdGoodsV2/remainComfirm", params, mHandler);
	}

	// 上传日志
	public static void joinRecords(String orderid, String content1,
			String content2, String content3, String content4,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("order_id", orderid);
		params.put("content", content1);
		params.put("studentInfo", content2);
		params.put("nextClassInfo", content3);
		params.put("needParentHelp", content4);

		ApiHttpClient.post("ProdGoodsV2/joinRecords", params, mHandler);
	}

	// 查看某一订单的日志
	public static void showOrderRecords(String orderId, String page,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("order_id", orderId);
		params.put("page", page);
		ApiHttpClient.post("ProdGoodsV2/showOrderRecords", params, mHandler);
	}

	// 家教查看所有有找家教需求的家长列表
	public static void searchParentV1(String page, Map<String, String> map,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();

		if (map != null) {
			for (Map.Entry<String, String> item : map.entrySet()) {
				params.put(item.getKey(), item.getValue());
			}
		}

		params.put("page", page);
		ApiHttpClient.post("ProdSearchParent/searchParentV1", params, mHandler);
	}

	// 联系所有传上来的家长列表
	public static void connectParentList(String parent,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("parents", parent);

		ApiHttpClient.post("ProdSearchParent/connectParentList", params,
				mHandler);
	}

	// 增加访问这个需求贴的访问人数
	public static void addVisitorNum(String id,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("requirement_id", id);

		ApiHttpClient.post("ProdSearchParent/addVisitorNum", params, mHandler);
	}

	// 注册:验证手机号并发送验证码
	public static void sendchecknum(String phone,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("phone", phone);
		params.put("role_type", "1");
		params.put("action", "1");

		ApiHttpClient.post("Register/sendchecknum", params, mHandler);
	}

	// 验证验证码
	public static void checkVerify(String checkNum,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("phone_check_num", checkNum);

		ApiHttpClient.post("Register/checkVerify", params, mHandler);
	}

	// 注册
	public static void register(String phone, String password,
			String rePassword, String cityId, String name, String sex,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("phone", phone);
		params.put("role_type", "1");
		params.put("user_password", MD5Utils.md5(password));
		params.put("user_password_check", MD5Utils.md5(rePassword));
		params.put("city_id", cityId);
		params.put("name", name);
		params.put("sex", sex);

		ApiHttpClient.post("Register/register", params, mHandler);
	}

	// 给校园大使发送验证码
	public static void sendchecknum2(String number,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("ambassador", number);
		ApiHttpClient.post("Register/sendchecknum2", params, mHandler);
	}

	// 校园大使验证码认证
	public static void checkVerify2(String checkNum,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("ambassador_check_num", checkNum);
		ApiHttpClient.post("Register/checkVerify2", params, mHandler);
	}

	// 引导1
	public static void prodRegister3(String school, String exp, String goodat,
			String address, AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("prod_school", school);
		params.put("prod_experience", exp);
		params.put("prod_goodat", goodat);
		params.put("prod_address", address);

		ApiHttpClient.post("ProdInfo/prodRegister3", params, mHandler);
	}	

	// 家教上传完图片完成注册
	// public static void prodFinishRegister(File head, File card,
	// AsyncHttpResponseHandler mHandler) {
	// RequestParams params = new RequestParams();
	// try {
	// params.put("prod_head_thumb", head);
	// params.put("prod_identity_path", card);
	// } catch (FileNotFoundException e) {
	// e.printStackTrace();
	// }
	//
	// ApiHttpClient.post("ProdInfo/prodFinishRegister", params, mHandler);
	// }

	// 上传头像
	public static void uploadProdHead(File head,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		try {
			params.put("prod_head_pic", head);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		ApiHttpClient.post("UploadFile/uploadProdHead", params, mHandler);
	}

	// 上传学生证
	public static void uploadStudentCard(File card,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		try {
			params.put("student_pic", card);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		ApiHttpClient.post("UploadFile/uploadStudentCard", params, mHandler);
	}

	// 家教找回密码先验证手机号并发送验证码
	public static void prodFindPsw1(String phone,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("prod_phone", phone);

		ApiHttpClient.post("ProdInfo/prodFindPsw1", params, mHandler);
	}

	// 验证修改密码的验证码
	public static void prodFindPsw2(String check,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();

		params.put("change_psw_check", check);
		ApiHttpClient.post("ProdInfo/prodFindPsw2", params, mHandler);
	}

	// 填写新密码
	public static void prodFindPsw3(String password, String rePassword,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("prod_password", password);
		params.put("prod_password_check", rePassword);

		ApiHttpClient.post("ProdInfo/prodFindPsw3", params, mHandler);
	}

	// 获取家教课程信息
	public static void MyCourses(AsyncHttpResponseHandler handler) {
		ApiHttpClient.post("GoodsConfig/MyCourses", handler);
	}

	// 删除课程
	public static void deleteCourses(String id,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.put("good_id", id);
		ApiHttpClient.post("GoodsConfig/deleteCourses", params, mHandler);
	}

	// 发布课程
	public static void addCourse(String kind_id, String price, String minmum,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();

		params.put("good_kind_id", kind_id);
		params.put("good_price", price);
		params.put("good_minnum", minmum);

		ApiHttpClient.post("GoodsConfig/addCourse", params, mHandler);
	}

	// 更新
	public static void AppUpdate(AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();

		params.put("android_student", String.valueOf(TDevice.getVersionCode()));
		ApiHttpClient.post("Index/update", params, mHandler);
	}
	
	//反馈
	public static void response(String content,AsyncHttpResponseHandler mHandler){
		RequestParams params=new RequestParams();
		params.put("content", content);
		
		ApiHttpClient.post("Index/questionSendmail", params, mHandler);	
	}

}








